package com.huibo.aigou.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.huibo.aigou.base.bo.AjaxResult;
import com.huibo.aigou.util.VelocityUtils;

@RestController
@RequestMapping("/velocity")
public class VelocityController {

	@PostMapping("/write")
	public AjaxResult write(@RequestParam("templateFilePathAndName") String templateFilePathAndName,
			                @RequestParam("targetFilePathAndName") String targetFilePathAndName,
			                @RequestBody Object model) {
		try {
			VelocityUtils.staticByTemplate(model, templateFilePathAndName, targetFilePathAndName);
			return AjaxResult.createInstance().setMsg("模板生成成功");
		}catch(Exception e) {
			e.printStackTrace();
			return AjaxResult.createInstance().setCode(500).setMsg("模板生成失败");
		}
	}
}
